<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>仪器二维码绑定</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<link href="../../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../../css/mui.poppicker.css" rel="stylesheet" />
		<link href="../../../css/task.css" rel="stylesheet" />
		<style>
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
			.item_box .item .name {
				height: auto;
				line-height: 20px;
			}
			.details_con .btm {
				height: 50px;
			}
			.item_box .btm li {
				line-height: normal;
				color: #333333;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">仪器二维码绑定</h1>
		</header>
		<div class="mui-content">
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="serialNo" placeholder="请输入序列号" />
				</div>
				<div class="btm autoHeight">
					<p class="selectBtn" id="sousuo" >查 询</p>
				</div>
			</div>
			<div class="details_con" style="margin: 30px 0 0 0;">
				<div class="item_box" id="liebiao">
					
					<!-- <div class="item">
						<div class="bar">
							<span class="number">1170001<img src="../../../images/icon_105.png" /></span>
						</div>
						<div class="name">
							安徽医科大学第一附属医院
						</div>
						<div class="type">
							<p>型号：<span>TV23</span><img src="../../../images/icon_106.png"/></p>
						</div>
						<ul class="btm">
							<li class="fr"><span class="i_8">绑定二维码</span></li>
						</ul>
					</div>
					<div class="item">
						<div class="bar">
							<span class="number">1170001<img src="../../../images/icon_105.png" /></span>
						</div>
						<div class="name">
							安徽医科大学第一附属医院
						</div>
						<div class="type">
							<p>型号：<span>TV23</span><img src="../../../images/icon_106.png"/></p>
						</div>
						<ul class="btm">
							<li class="fr"><span class="i_8">绑定二维码</span></li>
						</ul>
					</div> -->
					
				</div>
				<div style="height: 50px;"></div>
			</div>
		</div>
		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		
		<script type="text/javascript" charset="utf-8">
		
			 //mui初始化
			(function($, doc) {
				$.init();
				
				$.plusReady(function() {
					// 搜索方法
					h("#sousuo").tap(function(){
						initData();
					});			
				});
				
			}(mui, document));
			
			// 获取列表 
			function initData() {
				var serialNo = h("#serialNo").val();
				
				if(serialNo && serialNo.length < 3){
					app.toast("请输入至少3位字符再查询")
					return
				}
				if(serialNo==undefined || serialNo==""){
					app.closeWaiting()
					app.toast("请输入查询条件")
					return
				}
				app.showWaiting('加载中...')
				ajaxGet(BASE_URL + "cc/instrument/getInstrumentList", {
					"CustomerName": "",
					"serialNo": serialNo,
					"Div": "",
					"bu": ""
				}, function(data) {
					var html = "";
					h("#liebiao").html(html);
					if (data.code == 200) {
						if(data.data.code!=200){
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
							app.closeWaiting()
							return
						}
						if(data.data.data && data.data.data.length > 0){
							for(var i=0;i<data.data.data.length;i++){
								var dts = data.data.data[i];
								var Instrument_id = dts.Instrument_id;
								var serial_no = dts.serial_no;
								var Instrument_no = dts.Instrument_no;
								var qr_code = dts.Qrcode;
								if(!qr_code){
									qr_code = "未绑定"
								}
								var customer = dts.customer;
								var address = dts.address;
								html += '<div class="item" id="'+serial_no+'" Instrument_id="'+Instrument_id+'" Instrument_no="'+Instrument_no+'" customer="'+customer+'" address="'+address+'">'
									html += '<div class="bar">'
										html += '<span class="number"><img src="../../../images/icon_204.png" />'+serial_no+'</span>'
									html += '</div>'
									html += '<div class="name">'
										html += customer
									html += '</div>'
									html += '<div class="type">'
										html += '<p>型号：<span>'+Instrument_no+'</span><img src="../../../images/icon_223.png"/></p>'
										html += '<p>状态：<span>'+qr_code+'</span><img src="../../../images/icon_224.png"/></p>'
									html += '</div>'
									html += '<ul class="btm">'
										html += '<li class="fr"><span class="i_8" onclick=bindQrCode(\''+serial_no+'\')>绑定二维码</span></li>'
									html += '</ul>'
								html += '</div>';
							}
							h("#liebiao").html(html);
							app.closeWaiting()
						}else{
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
							app.closeWaiting()
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#liebiao").html(html);
						app.closeWaiting()
						app.toast(data.msg);
					}
				}, function(errorMsg) {
					app.closeWaiting();
					var html = '<div class="nodata">—— 暂无数据 ——</div>';
					h("#liebiao").html(html);
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			
			// 绑定二维码按钮
			function bindQrCode(serial_no){
				// app.toast(serial_no)
				app.jumpTo("/view/barcode/barcode.html","view/barcode/barcode.html",{
					"state": serial_no
				})
			}
			 
			// 扫描条形码回调方法
			function scaned(type, code, file, state) {
				console.log(state)
				console.log(type)
				console.log(code)
				console.log(file)
				var instSn = state
				var instrumentId = document.getElementById(state).getAttribute('Instrument_id');
				var instAddress = document.getElementById(state).getAttribute('address');
				var btnArray = ['确认绑定', '取消'];
				mui.confirm('确认绑定“'+code+'”吗？', '仪器二维码绑定', btnArray, function(e) {
					if (e.index == 0) {
						ajaxPost(BASE_URL + "cc/instrument/bingQrCode", {
							"instrumentId": instrumentId,
							"instSn": instSn,
							"accoutfseId": app.getUser().enginnerId,
							"instAddress": instAddress,
							"qrCode": code
						}, function(data) {
							if (data.code == 200) {
								app.toast(data.msg);
								initData();
							}else{
								app.toast(data.msg);
							}
						}, function(errorMsg) {
							console.log(JSON.stringify(errorMsg))
						});
					} else {
						app.toast("取消绑定")
					}
				})
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
